namespace designpatternsplusplus.regressions
{
    #region

    using System;
    using System.Collections.Generic;
    using decorator;
    using designpatternsplus.contracts;
    using NUnit.Framework;

    #endregion

    /// <summary>
    /// Support Statics for Regression
    /// </summary>
    public static class RegressionModel
    {
        static readonly EqualityComparer<Double> Comparer =
            EqualityComparer<Double>.Default;

        /// <summary>
        /// Performs the regression.
        /// </summary>
        /// <param name="myReceipt">My receipt.</param>
        /// <param name="WithTrace">if set to <c>true</c> [with trace].</param>
        /// <param name="prices">The prices.</param>
        public static void Validate
            (this ISalesReceipt myReceipt, bool WithTrace, params double[] prices)
        {
            var entryTraceMode = CoolCrapMarket.TraceOn;
            CoolCrapMarket.TraceOn = WithTrace;

            var _count = myReceipt.Count;
            var i = 0;
            Assert.IsTrue
                (_count == prices.Length,
                 "We did not process the asserted number of sales items. Assumed {0} got {1}",
                 prices.Length,
                 _count);

            foreach (var item in myReceipt)
            {
                var _amount = item.Amount();
                Assert.That(_amount > 0);
                Assert.That
                    (Comparer.Equals(_amount, prices[i]),
                     "Failed to Compare. Values were {0} and {1}",
                     _amount,
                     prices[i]);
                // ValidatedValues[item.Sku].BaseAmount);
                i++;
            }
            CoolCrapMarket.TraceOn = entryTraceMode;
        }

        /// <summary>
        /// Asserts the value and dumps to view
        /// </summary>
        /// <param name="itemToResolve">The item to resolve.</param>
        /// <param name="isEqual">The is equal.</param>
        /// <param name="ToDisplay">To display.</param>
        public static void ToViewWithAssert
            (this Func<double> itemToResolve, double isEqual, string ToDisplay)
        {
            var _itemToResolve = itemToResolve();

            Assert.IsTrue
                (_itemToResolve.Equals(isEqual),
                 "Unable to assert. Expected was {0} and we recieved {1} for {2}",
                 isEqual,
                 _itemToResolve,
                 ToDisplay);
        }
    }
}